package tree;

import hxd.fmt.hmd.Data.Material;
import view.Root_View;
import cmd.Root_Cmd;
import data.Root_Data;
import haxe.ds.GenericStack;

//根节点
class Root extends Tress {
    private static var m_instance : Root;
    public static var instance(get, null) : Root;

    private static function get_instance() {
        if(m_instance == null){
            m_instance = new Root();
        }
        return m_instance;
    }

    private var msgList : List<LeafMsg>;
    public var time : Float;
    //private var msg : LeafMsg;
    
    public function new() {
        super();
        msgList = new List<LeafMsg>();

        var root_data = new Root_Data();
        var root_cmd = new Root_Cmd();
        var root_view = new Root_View();
    
        AddLeaf(RData, root_data);
        AddLeaf(RCmd, root_cmd);
        AddLeaf(RView, root_view);
        
        m_isSingleLeafUpdate = false;

    }


    public override function OnEnter(last:LeafKind) {
        super.OnEnter(last);
        var keys = m_leafMap.keys();
        for (key in keys){
            PushLeaf(key);
        }
    }

    //添加命令
    public function AddMsg(msg:LeafMsg) {
        msgList.add(msg);
    }
    
    public function Start() {
        OnEnter(null);
    }

    //刷新
    public function Update(dt:Float) {
        var isOne = true;
        time += dt;
        while (isOne || msgList.length > 0){
            OnUpdate(msgList.pop());
            isOne = false;
        }
        
    }
    
}